<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class user_mod extends CI_Model {

    function user_mod()
    {
        parent::__construct();
        //$this->load->database('default',true);
    }
    
    function get_byemail($email)
    {
        $this->db->select('*');
        $this->db->where('email', $email);
        $i = $this->db->get('m_user', 1, 0);

        return $var = ($i->num_rows() > 0) ? $i->row_array() : false;
    }

    function get_byuser($username)
    {
        $this->db->select('username, email, about, path_image');
        $this->db->where('username', $username);
        
        $i = $this->db->get('m_user', 1, 0);

        return $var = ($i->num_rows() > 0) ? $i->row_array() : false;
    }

    function add($data=null)
    {
        if($data != null){
            $this->db->insert('m_user',$data);
        }
    }

    function get_bylogin($user = null,$pass = null)
    {
        $this->db->select('*');
        $this->db->where('username', mysql_real_escape_string($user));
        $this->db->where('password', mysql_real_escape_string($pass));
        $i = $this->db->get('m_user', 1, 0);

        $var = ($i->num_rows() > 0) ? $i->row_array() : false;
        return $var;
    }

    function update($data,$username)
    {
        $this->db->where('username', mysql_real_escape_string($username));
        $this->db->update('m_user', $data);
    }
    
    function get_user_record($username)
    {
        $this->db->select('r.id, s.title, s.album');
        $this->db->where('r.username', mysql_real_escape_string($username));
        $this->db->where('r.id_song', 's.id');
        $this->db->from('user_record r, m_song s');
        $i = $this->db->get();

        $var = ($i->num_rows() > 0) ? $i->result_array() : false;
        return $var;
    }
}